package com.dc.trans.steps.rowlevellog.logprocess;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.codec.binary.Base64;

/**
 * @ClassName: OuterMessageLog
 * @Description: TODO
 * @author zhangbinp
 * @date Aug 2, 2012 8:25:49 PM
 */
public class OuterMessageLog {
	private String id;
	private String pack_sn;
	private String message_id;
	private String trans_name;
	private String job_name;
	private String step_name;
	private char status;
	private String error_desc;
	private Date start_time;
	private Date end_time;
	private String node_name;
	private String node_id;
	private int step_no;
	private String message;
	private String blob_id;

	public String getBlob_id() {
		return blob_id;
	}

	public void setBlob_id(String blob_id) {
		this.blob_id = blob_id;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPack_sn() {
		return pack_sn;
	}

	public void setPack_sn(String pack_sn) {
		this.pack_sn = pack_sn;
	}

	public String getMessage_id() {
		return message_id;
	}

	public void setMessage_id(String message_id) {
		this.message_id = message_id;
	}

	public String getTrans_name() {
		return trans_name;
	}

	public void setTrans_name(String trans_name) {
		this.trans_name = trans_name;
	}

	public String getJob_name() {
		return job_name;
	}

	public void setJob_name(String job_name) {
		this.job_name = job_name;
	}

	public String getStep_name() {
		return step_name;
	}

	public void setStep_name(String step_name) {
		this.step_name = step_name;
	}

	public char getStatus() {
		return status;
	}

	public void setStatus(char status) {
		this.status = status;
	}

	public String getError_desc() {
		return error_desc;
	}

	public void setError_desc(String error_desc) {
		this.error_desc = error_desc;
	}

	public Date getStart_time() {
		return start_time;
	}

	public void setStart_time(Date start_time) {
		this.start_time = start_time;
	}

	public Date getEnd_time() {
		return end_time;
	}

	public void setEnd_time(Date end_time) {
		this.end_time = end_time;
	}

	public String getNode_name() {
		return node_name;
	}

	public void setNode_name(String node_name) {
		this.node_name = node_name;
	}

	public String getNode_id() {
		return node_id;
	}

	public void setNode_id(String node_id) {
		this.node_id = node_id;
	}

	public int getStep_no() {
		return step_no;
	}

	public void setStep_no(int step_no) {
		this.step_no = step_no;
	}

	public String getInsertBatchDatas(){
//		System.err.println("id="+id+",pack_sn="+pack_sn+",step_name="+step_name+",message_id="+message_id);
		if(id == null 
				|| pack_sn == null 
				|| message_id == null 
				|| trans_name == null 
				|| job_name == null 
				|| step_name == null 
				|| Character.isSpaceChar(status) 
				|| start_time == null
				|| end_time == null
				|| node_name == null 
				|| node_id == null )
		{
			return null;
		}
		
		StringBuilder sb = new StringBuilder("");
		sb.append(id).append(',');
		sb.append(pack_sn).append(',');
		sb.append(message_id).append(',');
		sb.append(trans_name).append(',');
		sb.append(job_name).append(',');
		sb.append(step_name).append(',');
		sb.append(status).append(',');
		if(error_desc != null){
			sb.append(new String(Base64.encodeBase64(error_desc.getBytes()))).append(',');
		}else{
			sb.append("'',");
		}
		sb.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(start_time)).append(',');
		sb.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(end_time)).append(',');
		sb.append(node_name).append(',');
		sb.append(node_id).append(',');
		sb.append(step_no).append(',');
		if(blob_id != null){
			sb.append(blob_id).append(',');
			if(message != null){
				sb.append(new String(Base64.encodeBase64(message.getBytes())));
			}
		}else{
			sb.deleteCharAt(sb.length()-1);
		}     
		return sb.toString();
	}
}
